//
//  NSStringCategoriesTests.swift
//  Tests
//
//  Created by LL on 2023/4/7.
//

import XCTest

final class NSStringCategoriesTests: XCTestCase {
    func test_isEmpty() throws {
        XCTAssertTrue(NSString("").isEmpty)
        XCTAssertFalse(NSString(" ").isEmpty)
        XCTAssertFalse(NSString("1232").isEmpty)
        XCTAssertFalse(NSString("jfkjb").isEmpty)
        XCTAssertFalse(NSString("\n\t\r").isEmpty)
        XCTAssertFalse(NSString("汉字").isEmpty)
    }
    
    
    func test_rangeOfAll() throws {
        XCTAssertEqual(NSString("").rangeOfAll, NSRange(location: 0, length: 0))
        XCTAssertEqual(NSString("123").rangeOfAll, NSRange(location: 0, length: 3))
        XCTAssertEqual(NSString("      ").rangeOfAll, NSRange(location: 0, length: 6))
        XCTAssertEqual(NSString("jfkjb").rangeOfAll, NSRange(location: 0, length: 5))
        XCTAssertEqual(NSString("\n\t\r").rangeOfAll, NSRange(location: 0, length: 3))
        XCTAssertEqual(NSString("汉字").rangeOfAll, NSRange(location: 0, length: 2))
    }
    
    
    func test_lilSubstring() throws {
        XCTAssertNil("".lilSubstring(with: NSRange(location: -1, length: 0)))
        XCTAssertNil("".lilSubstring(with: NSRange(location: 1, length: -1)))
        XCTAssertEqual("".lilSubstring(with: NSRange(location: 0, length: 0)), "")
        
        let content: NSString = "appendingPathComponent"
        
        XCTAssertEqual(content.lilSubstring(with: NSRange(location: 0, length: content.length)), content)
        XCTAssertEqual(content.lilSubstring(with: NSRange(location: 0, length: 1)), "a")
        XCTAssertEqual(content.lilSubstring(with: NSRange(location: 1, length: 1)), "p")
        XCTAssertEqual(content.lilSubstring(with: NSRange(location: content.length - 1, length: 1)), "t")
        XCTAssertNil(content.lilSubstring(with: NSRange(location: content.length + 1, length: 1)))
        XCTAssertNil(content.lilSubstring(with: NSRange(location: content.length - 1, length: 2)))
    }
}
